package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.IdOpt;
import org.akomantoso.core.io.Externalizable;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * The complex type metaopt defines the content model and attributes shared by
 * all metadata elements. Here the id attribute is optional
 * 
 * <pre>
 * <xsd:complexType name="metaopt">
 * 		<xsd:attributeGroup ref="idopt"/>
 * </xsd:complexType>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 * 
 */
public class MetaOpt implements IdOpt, Externalizable {

	private String _id;
	private String _evolvingId;
	
	/**
	 * @see org.akomantoso.core.data.attribute.IdOpt#getId()
	 */
	public String getId() {
		return _id;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdOpt#setId(java.lang.String)
	 */
	public void setId(String id) {
		_id = id;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdOpt#getEvolvingId()
	 */
	public String getEvolvingId() {
		return _evolvingId;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdOpt#setEvolvingId(java.lang.String)
	 */
	public void setEvolvingId(String evolvingId) {
		_evolvingId = evolvingId;
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#writeExternal(org.akomantoso.core.io.Output)
	 */
	public <T extends Output> void writeExternal(T out) throws IOException {
		OutputUtil.writeAttribute(out, IdOpt.ATTRIBUTE_ID, _id);
		OutputUtil.writeAttribute(out, IdOpt.ATTRIBUTE_EVOLVING_ID, _evolvingId);
	}
	
	/**
	 * @see org.akomantoso.core.io.Externalizable#readExternal(org.akomantoso.core.io.Input)
	 */
	public <T extends Input> void readExternal(T in) throws IOException {
		_id = in.readAttribute(IdOpt.ATTRIBUTE_ID);
		_evolvingId = in.readAttribute(IdOpt.ATTRIBUTE_EVOLVING_ID);
	}
	
}